/*
 * @lc app=leetcode.cn id=1299 lang=typescript
 *
 * [1299] 将每个元素替换为右侧最大元素
 */

// @lc code=start
function replaceElements(arr: number[]): number[] {
    let max = -1;
    for (let i = arr.length - 1; i >= 0; i--) {
        const element = arr[i];
        arr[i] = max;
        max = Math.max(max, element);
    }
    return arr;
}
// @lc code=end
